package ui.role
{
	import flash.geom.Point;
	import flash.display.BitmapData;
	import flash.display.Bitmap;
	import adapter.role.RoleAdapterBase;
	import ui.common.SpriteObject;

	/**
	 * @author Administrator
	 */
	public class RoleBaseUI extends SpriteObject
	{
		private var _bmdArr:Array;
		private var _roleModel:Bitmap;
		private var _bmdIndex:int;
		
		public function RoleBaseUI()
		{
			super();
			init();
		}
		
		private function init():void
		{
			_roleModel = new Bitmap();
			addChild(_roleModel);
		}
		
		protected function get roleBaseAdapter():RoleAdapterBase
		{
			return adapter  as RoleAdapterBase;
		}
		
		public function oneTick():void
		{
			var bmd:BitmapData;
			if(_bmdArr)
			{
				if (_bmdArr[_bmdIndex])
				{
					bmd = _bmdArr[_bmdIndex].bmd as BitmapData;
					if (bmd)
					{
						_roleModel.bitmapData = bmd;
						_roleModel.x           = -_bmdArr[_bmdIndex].centerX;
						_roleModel.y           = -_bmdArr[_bmdIndex].centerY;
					}
				}
				_bmdIndex++;
				if(_bmdIndex >= _bmdArr.length)
				{
					_bmdIndex = 0;
				}
			}
		}
		
		public function updatePostion(pos:Point) : void
		{
			if (roleBaseAdapter && pos)
			{
				x = pos.x;
				y = pos.y;
			}
		}

		override public function update() : void
		{
			super.update();
			if (roleBaseAdapter)
			{
				_bmdIndex = 0;
				_bmdArr = roleBaseAdapter.bmdArr;
			}
		}
	}
}
